package com.yygo.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * Created by huanli on 2015/11/24.
 */
@Entity
@Table(name = "dealer_rule")
public class DealerRule extends BaseObject{
    private static final long serialVersionUID = -8463692134221785043L;
    private Long id;
    private String code;
    private String description;
    private boolean status;
    private Dealer dealer;

    @Column(length = 4)
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Column
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column
    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    @ManyToOne()
    @JoinColumn(name="dealer_id")
    public Dealer getDealer() {
        return dealer;
    }

    public void setDealer(Dealer dealer) {
        this.dealer = dealer;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return code + ": " + description;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof DealerRule)) {
            return false;
        }

        final DealerRule dealerRule = (DealerRule) o;

        return !(id != null ? !id.equals(dealerRule.getId()) : dealerRule.getId() != null);
    }

    @Override
    public int hashCode() {
        return id.intValue()+code.hashCode()+description.hashCode() ;
    }
}
